package com.bishe.demo.modules.hotel.hotelRoom.dao;

import com.bishe.demo.modules.account.entity.User;
import com.bishe.demo.modules.hotel.hotelRoom.entity.Room;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Mapper
@Repository
public interface RoomDao {
    @Insert("insert into hotel_room values(null,#{roomNum},#{roomName},#{breakfastNum},#{roomDetail},#{roomCost},#{payType})")
    @Options(useGeneratedKeys = true, keyProperty = "roomId", keyColumn = "room_id")
    void insertRoom(Room room);

    @Select("select * from hotel_room hr left join hotel_room_user hru on hru.room_id=hr.room_id where hru.user_id=#{hotelId}")
    @Results(id = "roomResult", value = {
            @Result(property = "roomId", column = "room_id"),
            @Result(property = "beds", column = "room_id",
                    javaType = List.class,
                    many = @Many(select = "com.bishe.demo.modules.hotel.hotelRoom.dao.BedDao.getBedsByRoomId")),
            @Result(property = "hotelImages", column = "room_id",
                    javaType = List.class,
                    many = @Many(select = "com.bishe.demo.modules.hotel.common.dao.HotelImageDao.getImagesByRoomId")),
            @Result(property = "user", column = "room_id",
                    javaType = User.class,
                    many = @Many(select = "com.bishe.demo.modules.account.dao.UserDao.getUserByrRoomId"))
    })
    List<Room> getRoomsByHotelId(int hotelId);

    @Select("select * from hotel_room where room_id=#{roomId}")
    Room getRoomByRoomId(int roomId);

    @Delete("delete from hotel_room where room_id=#{roomId}")
    void deleteRoomByRoomId(int roomId);
}
